package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class BitmapUtils
	{
		public function BitmapUtils()
		{
		}
		
		public static function cropBitmap(oriBitmap:Bitmap,rect:Rectangle):Bitmap
		{
			var copyBitmapDate:BitmapData = new BitmapData(rect.width,rect.height);
			copyBitmapDate.copyPixels(oriBitmap.bitmapData,rect,new Point());
			return new Bitmap(copyBitmapDate);
		}
		
		public static function rotateBitmap( oriBitmap:Bitmap,angle:Number ):Bitmap
		{
			var m:Matrix = oriBitmap.transform.matrix;
			var rotatePointX:Number = oriBitmap.width/2;
			var rotatePointY:Number = oriBitmap.height/2;
			var rotatePoint:Point = new Point(rotatePointX,rotatePointY);
			var transformPoint:Point = m.transformPoint(rotatePoint);
			m.translate( -rotatePointX,-rotatePointY );
			m.rotate( angle*Math.PI/180);
			m.translate( rotatePointX,rotatePointY );
			var rotateBitmap:BitmapData = new BitmapData( oriBitmap.width,oriBitmap.height );
			rotateBitmap.draw(oriBitmap,m);
			return new Bitmap( rotateBitmap );
			
		}
	}
}